package com.education.platform.api.controller.user;

import com.education.platform.api.config.ThreadUser;
import com.education.platform.api.vo.request.AccountVipOpenVo;
import com.education.platform.common.util.DateUtils;
import com.education.platform.dao.entity.AccountDO;
import com.education.platform.dao.entity.UserBaseDO;
import com.education.platform.common.util.BeanUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.education.platform.api.service.AccountService;
import org.springframework.validation.annotation.Validated;
import com.education.platform.api.vo.response.AccountResponseVO;

import java.util.Date;

/**
* describe: 账户
* @author : tomato
* @date: 2020-06-06 02:55:51.638
**/
@RestController
@Api("账户")
@RequestMapping("account")
@Validated
public class AccountController {

    private static final Logger LOGGER = LoggerFactory.getLogger(AccountController.class);

	@Autowired
    private AccountService accountService;


    /**
     * 获取账户数据
     * @param
     * @return 分页参数
     */
    @ApiOperation(value = "获取账户数据")
    @PostMapping("getAccount")
	public AccountResponseVO getAccount(){
        AccountDO query = new AccountDO();
        UserBaseDO user= ThreadUser.getUser(UserBaseDO.class);
        query.setUserId(user.getId());
        AccountDO dto = accountService.get(query);
        AccountResponseVO responseVO = BeanUtil.convert(dto,AccountResponseVO.class);
//        if(MemberTypeEnum.VIP.getValue().equals(responseVO.getMemberType())){
//            //距离过期天数
//            responseVO.setExpireDay(DateUtils.daydiff(new Date(),dto.getExpireDate()));
//        }else{
//            //不是vip
//            responseVO.setExpireDate(null);
//        }
        responseVO.setBeansCount(dto.getBeanNumber()==null?0:dto.getBeanNumber());
        return  responseVO;
    }

}
